var mainJS = function (){
    var mainJS = this;
    this.URL = {
        articleList : "/articleList",
        categoryList : "/categoryList"
    }

    var indexList = function (){
        $.ajax({
            url:mainJS.URL.categoryList,
            type: "GET",
            dataType:"text",
            success: function (e) {   //成功后回调
                var sdata = eval("("+e+")")
                console.log("数据"+JSON.stringify(sdata));
                new Vue({
                        el: '#topnav',
                        data: {
                        items: sdata
                        }
                    })
            },
            error: function(e){    //失败后回调
                console.log("错误")
                console.log(e);
            },
            beforeSend: function(){  //发送请求前调用，可以放一些"正在加载"之类额话
                console.log("正在加载");
            }
        })
        $.ajax({
            url:mainJS.URL.articleList,
            type: "GET",
            dataType:"json",
            success: function (e) {   //成功后回调
                console.log(e.rows)
                new Vue({
                    el: '#blogRecommendList',
                    data: {
                        items: e.rows
                    },
                    computed: {
                        items2: function () {
                            return this.items.filter(function (items) {
                                items.content = getCont(items.content);
                                items.createTime = items.createTime.substring(0,10);
                                return items;
                            })
                        }

                    }
                })
                pageListInif();
            },
            error: function(e){    //失败后回调
                console.log("错误")
                console.log(e);
            },
            beforeSend: function(){  //发送请求前调用，可以放一些"正在加载"之类额话
                console.log("正在加载");
            }
        })
    }
    var pageListInif = function(){
        /* initiate the plugin */
        $("#holder").jPages({
            containerID  : "blogRecommendList",
            perPage: 5,
            startPage: 1,
            startRange: 2,
            midRange: 3,
            endRange: 2,
            callback    : function( pages, items ){
                pages.count = 10;
                items.count = 10;
                console.log(pages);
                console.log(items.showing);
            }
        });
    }
    this.init = function (){
        indexList();
    }
    function getCont(value){
        var start_ptn = /(<.[^>]+>)*/gmi;		//过滤标签开头
        var end_ptn = /<\/?\w+>$/;			//过滤标签结束
        var space_ptn = /(&nbsp;)*/;			//过滤空格
        var c1 = value.replace(start_ptn,"").replace(end_ptn).replace(space_ptn,"");
        if(c1.length > 250){
            c1 = c1.substring(0,230)+" ...";
        }
        return c1;
    }
}

$(function (){
    new mainJS().init();
})